/**
 * work_status_code
 * 待转正          7
 * 顺利转正         1
 * 延期转正         8
 * 不预转正         9
 * @param defaultParams
 */


function main(defaultParams) {
    let self = this;
    debugger
    self.$$("text_58n46y").$$setValue(defaultParams.name);
    api.EXEC_FORMULA("TREE_QUERY_CHILDRENS('00c0bc5c-16c1-4745-9cf9-8ec57e23659d','" + defaultParams.id + "',['unit_id'])").then((res) => {

        let pageTableList = self.$$("page_widget_list_1b7r5t");
        let pageTableList1 = self.$$("page_widget_list_dbzjt6");
        let pageTableList2 = self.$$("page_widget_list_1lm05c");
        let pageTableList3  = self.$$("page_widget_list_3h00ae");

        if (pageTableList && pageTableList.dataEngine && pageTableList.dataEngine.state) {
            const tableComp = pageTableList.dataEngine.state.getElement("table_ba6yfm");
            const tableComp1 = pageTableList1.dataEngine.state.getElement("table_ba6yfm");
            const tableComp2 = pageTableList1.dataEngine.state.getElement("table_ba6yfm");
            const tableComp3 = pageTableList1.dataEngine.state.getElement("table_ba6yfm");
            tableComp.loading = true;
            tableComp1.loading = true;
            tableComp2.loading = true;
            tableComp3.loading = true;

            if (tableComp) {

                selectByUnitId(pageTableList, res.result)
                selectByUnitId(pageTableList1, res.result)
                selectByUnitId(pageTableList2, res.result)
                selectByUnitId(pageTableList3, res.result)

                tableComp.onRefresh();
                tableComp1.onRefresh();
                tableComp2.onRefresh();
                tableComp3.onRefresh();
            }
        }

    }).catch(err => {
        self.$message.error(err.message); // 显示错误提示信息
    });
}



/**
 * 通过部门进行过滤
 * @param {*} pageTableList
 * @param {*} unit_id
 */
function selectByUnitId(pageTableList, unit_id) {

    var members = pageTableList.dataEngine.state.layout.props.dataSet.filterData.filter.members

    members = members.filter(function (item) {
        return item.uniqueIdentify !== "unitIdFilter";
    });

    members.push({
        "uniqueIdentify": "unitIdFilter",
        field: "0bbd3112-35c4-4013-949c-22ffcf0f7b3e",
        fieldName: "unit_id",
        "fieldType": "TYPE_INTEGER",
        valueType: "Constant",
        values: unit_id || [],
        value: "",
        operate: "In", // 范围查询
        className: "Single",
        treeUnitIdFiter: "1"
    });
    var filter = {
        "combine": "And",
        "className": "List",
        "members": members
    };

    pageTableList.dataEngine.state.layout.props.dataSet.filterData = {
        "enabled": true,
        "filter": filter,
        "filterType": "FILTER",
        "rawCondition": {},
        "rawFormula": ""
    }

}



function main() {
    // 获取页面树实例
    var pageTreeEle = this.$$element("page_tree_gcjy66");
    // 获取树渲染实例
    var treeRenderEle = pageTreeEle.$$getRenderElement();
    // 获取当前树实例
    var treePanelEle = treeRenderEle.$$getTreeElement();
    // 获取第一个节点
    var firstNode = treePanelEle.$$getRootNode()[0].id;
    treePanelEle.$$clickNode({ key: firstNode });
}




function main() {

    let pageTreeEle = this.$$("page_tree_b28fi0");

    pageTreeEle.$children[0].$$setExtraParams({
        patrolFlag: '1,0',
        workStatusCode: "7",
        validFlag: "1"
    })
    let treeComp = pageTreeEle.dataEngine.state.getElement("tree_panel_78vxbg");
    if (treeComp) {
        treeComp.$$refreshData();
    }

}


function onTabClick(tab) {
    let workStatusCodeValue = '';
    if (tab == 2) {
        workStatusCodeValue = '1';
    } else if (tab == 3){
        workStatusCodeValue = '8';
    }else if(tab == 4){
        workStatusCodeValue = '9';
    }else {
        workStatusCodeValue = '7';
    }
    let pageTreeEle = this.$$("page_tree_b28fi0");

    pageTreeEle.$children[0].$$setExtraParams({
        patrolFlag: '1,0',
        workStatusCode: workStatusCodeValue,
        validFlag: "1"
    })
    let treeComp = pageTreeEle.dataEngine.state.getElement("tree_panel_78vxbg");
    if (treeComp) {
        treeComp.$$refreshData();
    }

}
